Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Sound

| Previous | Chapter contents | Chapter top | Section top | Next |

Playing Sound Resources

You can use the SysBeep procedure to play the system alert sound. Alert sounds are stored in the System file as format 1 'snd ' resources. You can use the SndPlay function to play the sounds that are stored in any 'snd ' resource, either format 1 or format 2.

The SysBeep and SndPlay routines are the highest-level sound routines that the Sound Manager provides. Depending on the needs of your application, you might be able to accomplish all desired sound-related activity simply by using SysBeep to produce the system alert sound or by using SndPlay to play other sounds that are stored as 'snd ' resources.

SysBeep

You can use the SysBeep procedure to play the system alert sound.

PROCEDURE SysBeep (duration: Integer);
duration
The duration (in ticks) of the resulting sound. This parameter is ignored except on a Macintosh Plus, Macintosh SE, or Macintosh Classic when the system alert sound is the Simple Beep. The recommended duration is 30 ticks, which equals one-half second.

DESCRIPTION

The SysBeep procedure causes the Sound Manager to play the system alert sound at its current volume. If necessary, the Sound Manager loads into memory the sound resource containing the system alert sound and links it to a sound channel. The user selects a system alert sound in the Alert Sounds subpanel of the Sound control panel.

The volume of the sound produced depends on the current setting of the system alert sound volume, which the user can adjust in the Alert Sounds subpanel of the Sound control panel. The system alert sound volume can also be read and set by calling the GetSysBeepVolume and SetSysBeepVolume routines. If the volume is set to 0 (silent) and the system alert sound is enabled, calling SysBeep causes the menu bar to blink once.

SPECIAL CONSIDERATIONS

Because the SysBeep procedure moves memory, you should not call it at interrupt time.

SEE ALSO

For information on enabling and disabling the system alert sound, see the description of SndGetSysBeepState and SndGetSysBeepState on [link] . For information on reading or adjusting the system alert sound volume, see "Controlling Volume Levels" .

SndPlay

You can use the SndPlay function to play a sound resource that your application has loaded into memory.

FUNCTION SndPlay (chan: SndChannelPtr; sndHdl: Handle;
                                         async: Boolean): OSErr;
chan
A pointer to a valid sound channel. You can pass NIL instead of a pointer to a sound channel if you want the Sound Manager to internally allocate a sound channel in your application's heap zone.
sndHdl
A handle to the sound resource to play.
async
A Boolean value that indicates whether the sound should be played asynchronously ( TRUE ) or synchronously ( FALSE ). This parameter is ignored (and the sound plays synchronously) if NIL is passed in the first parameter.

DESCRIPTION

The SndPlay function attempts to play the sound located at sndHdl , which is expected to have the structure of a format 1 or format 2 'snd ' resource. If the resource has not yet been loaded, the SndPlay function fails and returns the resProblem result code.

All commands and data contained in the sound handle are then sent to the channel. Note that you can pass SndPlay a handle to some data created by calling the Sound Input Manager's SndRecord function as well as a handle to an actual 'snd ' resource that you have loaded into memory.

In some versions of system software prior to system software version 7.0, the SndPlay function will not work properly with sound resources that specify the sound data type twice. This might happen if a resource specifies that a sound consists of sampled-sound data and an application does the same when creating a sound channel. For more information on this problem, see "Allocating Sound Channels" .

The chan parameter is a pointer to a sound channel. If chan is not NIL , it is used as a valid channel. If chan is NIL , an internally allocated sound channel is used. If you do supply a sound channel pointer in the chan parameter, you can play the sound asynchronously. When a sound is played asynchronously, a callback procedure can be called when a callBackCmd command is processed by the channel. (This procedure is the callback procedure supplied to SndNewChannel .) See "Playing Sounds Asynchronously" for more information on playing sounds asynchronously. The handle you pass in the sndHdl parameter must be locked for as long as the sound is playing asynchronously.

If a format 1 'snd ' resource does not specify which type of sound data is to be played, SndPlay defaults to square-wave data. SndPlay also supports format 2 'snd ' resources using sampled-sound data and a bufferCmd command. Note that to use SndPlay and sampled-sound data with a format 1 'snd ' resource, the resource must include a bufferCmd command.

SPECIAL CONSIDERATIONS

Because the SndPlay function moves memory, you should not call it at interrupt time.

RESULT CODES

noErr

0

No error

notEnoughHardwareErr

-201

Insufficient hardware available

resProblem

-204

Problem loading the resource

badChannel

-205

Channel is corrupt or unusable

badFormat

-206

Resource is corrupt or unusable

SEE ALSO

For an example of how to play a sound resource using the SndPlay function, see the chapter "Introduction to Sound on the Macintosh" in this book.

For information on playing a sound resource without using the SndPlay function, see "Playing Sounds Using Low-Level Routines" .


© 1999 Apple Computer, Inc.

| Previous | Chapter contents | Chapter top | Section top | Next |